const authMenus = {
  // token : options  roles:['ADMIN']
  'f2a986c910e040e4891dd67a57d6136d': {
    'menus': [
      {
        name: 'sys',
        title: '系统管理',
        icon: 'el-icon-s-tools',
        url: '',
        children: [
          {
            name: 'user',
            title: '用户管理',
            icon: 'el-icon-user-solid',
            url: 'sys/user',
            children: []
          },
          {
            name: 'role',
            title: '角色管理',
            icon: 'el-icon-s-custom',
            url: 'sys/role',
            children: []
          },
          {
            name: 'menu',
            title: '菜单管理',
            icon: 'el-icon-menu',
            url: 'sys/menu',
            children: []
          },
          {
            name: 'param',
            title: '参数管理',
            icon: 'el-icon-coin',
            url: 'sys/param',
            children: []
          }
        ]
      },
      {
        name: 'monitor',
        title: '监控统计',
        icon: 'el-icon-s-platform',
        url: '',
        children: [
          {
            name: 'log',
            title: '系统日志',
            icon: 'el-icon-date',
            url: 'monitor/log',
            children: []
          },
          {
            name: 'dailyCount',
            title: '日常统计',
            icon: 'el-icon-s-order',
            url: 'monitor/dailyCount',
            children: []
          }
        ]
      }
    ],
    'perms': ['sys:user:view', 'sys:user:add', 'sys:user:edit', 'sys:user:switch', 'sys:user:auth', 'sys:role:view', 'sys:role:add', 'sys:role:edit', 'sys:role:del', 'sys:role:auth', 'sys:menu:view', 'sys:menu:add', 'sys:menu:edit', 'sys:menu:del', 'sys:param:view', 'sys:param:add', 'sys:param:edit', 'sys:param:del', 'monitor:log:view']
  },
  // token : options  roles:['MANAGER', 'USER']
  'd2a45245828e4fb8aafd7337c2464971': {
    'menus': [
      {
        name: 'sys',
        title: '系统管理',
        icon: 'el-icon-s-tools',
        url: '',
        children: [
          {
            name: 'user',
            title: '用户管理',
            icon: 'el-icon-user-solid',
            url: 'sys/user',
            children: []
          },
          {
            name: 'role',
            title: '角色管理',
            icon: 'el-icon-s-custom',
            url: 'sys/role',
            children: []
          },
          {
            name: 'menu',
            title: '菜单管理',
            icon: 'el-icon-menu',
            url: 'sys/menu',
            children: []
          }
        ]
      },
      {
        name: 'monitor',
        title: '监控统计',
        icon: 'el-icon-s-platform',
        url: '',
        children: [
          {
            name: 'log',
            title: '系统日志',
            icon: 'el-icon-date',
            url: 'monitor/log',
            children: []
          }
        ]
      }
    ],
    'perms': ['sys:user:view', 'sys:user:add', 'sys:user:edit', 'sys:user:switch', 'sys:user:auth', 'sys:role:view', 'sys:role:add', 'sys:role:edit', 'sys:role:del', 'sys:role:auth', 'sys:menu:view', 'sys:menu:add', 'sys:menu:edit', 'sys:menu:del', 'monitor:log:view']
  },
  '74470154c77a4c90a7536438392f5c17': {
    'menus': [],
    'perms': []
  },
  'b09c283d274548a1b6d967a5ad211cf2': {
    'menus': [],
    'perms': []
  }
}

let userList = [
  {
    id: '001',
    loginName: 'admin',
    alias: '管理员',
    password: '111111',
    avatar: '',
    desc: '这家伙很懒什么也没有留下',
    roles: ['ADMIN'],
    token: 'f2a986c910e040e4891dd67a57d6136d'
  },
  {
    id: '002',
    loginName: 'bangzz',
    alias: '周大侠',
    password: '111111',
    avatar: '',
    status: 1,
    roles: ['MANAGER', 'USER'],
    token: 'd2a45245828e4fb8aafd7337c2464971'
  },
  {
    id: '003',
    loginName: 'user1',
    alias: '用户甲',
    password: '111111',
    avatar: '',
    status: 1,
    roles: ['USER'],
    token: '74470154c77a4c90a7536438392f5c17'
  },
  {
    id: '004',
    loginName: 'user2',
    alias: '用户乙',
    password: '111111',
    avatar: '',
    status: 0,
    roles: ['USER'],
    token: 'b09c283d274548a1b6d967a5ad211cf2'
  }
]

export default {
  'post|/login/auth': option => {
    let ret = {code: 200, msg: '', data: null}
    if (option.body) {
      const params = JSON.parse(option.body)
      const data = userList.find(item => {
        return item.loginName === params.username
      })
      if (data) {
        if (data.password === params.password) {
          ret.msg = '登录成功!'
          ret.data = {
            userInfo: {
              alias: data.alias,
              avatar: data.avatar
            },
            access_token: data.token,
            refresh_token: ''
          }
        } else {
          ret.code = 401
          ret.msg = '用户密码不正确，请重新输入!'
        }
      } else {
        ret.code = 401
        ret.msg = '登录失败，此用户不存在!'
      }
    }
    return ret
  },
  'get|/base/authMenu': option => {
    let ret = {code: 200, msg: '', data: null}
    const url = option.url
    const token = url.split('/')[url.split('/').length - 1]
    const data = authMenus[token]
    if (data) {
      ret.data = data
    } else {
      ret.code = 500
      ret.msg = 'menu is not found through token[' + token + ']!'
    }
    return ret
  },
  'put|/base/password': option => {
    let ret = {code: 200, msg: '', data: null}
    const params = JSON.parse(option.body)
    console.log(params)
    ret.msg = '修改密码成功！请关闭mockjs开启后台体验完整功能！'
    return ret
  },
  'get|/base/userInfo': option => {
    let ret = {code: 200, msg: '', data: null}
    ret.data = {
      userName: 'mockJsTestUser',
      userAlias: 'mockjs模拟数据',
      userSex: 1,
      userPhone: '13660270951',
      userEmail: '',
      userDesc: '请关闭mockjs开启后台体验完整功能！'
    }
    return ret
  },
  'put|/base/userInfo': option => {
    let ret = {code: 200, msg: '', data: null}
    const params = JSON.parse(option.body)
    console.log(params)
    ret.msg = '修改成功！请关闭mockjs开启后台体验完整功能！'
    return ret
  }
}
